package com.apes.sms.systemSetting.model;

import com.apes.framework.api.SpringManager;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.party.repository.PartyRoleRepository;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;


/**
 * 功能：方案打印设置表
 *
 * @author zyl
 * @create 2022-06-30 14:02
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ServicePlanPrint.CONST_TABLE_NAME)
public class ServicePlanPrint extends Model {

    public static final String CONST_TABLE_NAME = "mas_service_plan_print";

    @Id
    @Column(name = "id", length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "打印设置编码")
    @Comment("打印设置编码")
    private String id;

    @Column(name = "range", columnDefinition = "number(1,0) default 0")
    @Comment("适用范围")
    private String range;  // 1 : 公司；0 ：单店

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("业务部门")
    private Dept dept;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("所属公司")
    private PartyRole company;

    @Column(name = "address", length = 500)
    @Comment("地址")
    private String address;

    @Column(name = "telephone", length = 20)
    @Comment("联系电话")
    private String telephone;

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "LOGO",columnDefinition = "CLOB")
    @Comment("LOGO")
    private String logo;

    @Column(name = "logo_id", length = 30)
    @Comment("logo_id")
    private String logoId;

    @Column(name = "reminder", columnDefinition = "CLOB")
    @Comment("温馨提示")
    private String reminder;

    @Column(name = "car_curing", columnDefinition = "CLOB")
    @Comment("养车攻略")
    private String carCuring;

    @Column(name = "confirmed_reminder", columnDefinition = "CLOB")
    @Comment("方案确认温馨提示")
    private String confirmedReminder;

    @Column(name = "confirmed_car_curing", columnDefinition = "CLOB")
    @Comment("方案确认养车攻略")
    private String confirmedCarCuring;

    @Transient
    private PartyRole _creator;
    @Transient
    private String range1 = "单店";

    @Transient
    private Boolean init = true;

    @Transient
    public PartyRole get_creator() {
        if(this.getCreator() == null) return null;
        return SpringManager.getBean(PartyRoleRepository.class).findOne(this.getCreator());
    }
}
